package com.hucejakie.geoquiz;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.view.menu.ShowableListMenu;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.widget.Button;
import android.widget.TextView;

public class CheatActivity extends AppCompatActivity {


    private static final String EXTRA_ANSWER_IS_TRUE = "com.hucejakie.geoquiz.extr_answer_is_true";
    private static final String EXTRA_ANSWER_SHOWN = "com.hucejakie.geoquiz.extr_answer_shown";
    private boolean mAnswerIsTrue;
    private Button mShowAnswer;
    private TextView mAnswerTextView;
    private TextView mOSAPILevel;
    public static Intent newIntent(Context packageContext, boolean answerIsTrue) {
        Intent i = new Intent(packageContext, CheatActivity.class);

        i.putExtra(EXTRA_ANSWER_IS_TRUE, answerIsTrue);
        return i;
    }    ;

    public static boolean wasAnswerShown(Intent data) {

       return data.getBooleanExtra(EXTRA_ANSWER_SHOWN,false);

    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cheat);

        mAnswerTextView = (TextView) findViewById(R.id.answer_text_view);
        mOSAPILevel= (TextView) findViewById(R.id.os_api_level);
        mOSAPILevel.setText("Current SDK API Level:"+String.valueOf(Build.VERSION.SDK_INT));

        mShowAnswer = (Button) findViewById(R.id.show_answer_button);
        mShowAnswer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mAnswerIsTrue == true) {
                    mAnswerTextView.setText(R.string.true_button);
                } else {
                    mAnswerTextView.setText(R.string.false_button);
                }

                setAnswerShownResult(true);

                int cx= mShowAnswer.getWidth();
                int yx=mShowAnswer.getHeight();
                float radius=mShowAnswer.getWidth();
                if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.LOLLIPOP)
                {
                    Animator anim = ViewAnimationUtils.createCircularReveal(mShowAnswer, cx, yx, radius, 0);
                    anim.addListener(
                            new AnimatorListenerAdapter() {
                                @Override
                                public void onAnimationEnd(Animator animation) {
                                    super.onAnimationEnd(animation);
                                    mShowAnswer.setVisibility(View.INVISIBLE);
                                }
                            }
                    );
                    anim.start();
                }
                else
                {
                    mShowAnswer.setVisibility(View.INVISIBLE);

                }

            }
        });

        mAnswerIsTrue = getIntent().getBooleanExtra(EXTRA_ANSWER_IS_TRUE, false);


    }

    ;

    private void setAnswerShownResult(boolean isAnswerShown) {
        Intent data = new Intent();
        data.putExtra(EXTRA_ANSWER_SHOWN, isAnswerShown);
        setResult(RESULT_OK, data);
    };



}
